﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MazeRaider
{
    class DfsAlgorithm : IAlgorithm
    {
        private Robot[] robots;
        private DfsAgent[] agents;
        private SharedMemory memory;
        private MessageQueue queue;

        public DfsAlgorithm(Robot[] robots)
        {
            this.robots = robots;
        }

        public void Initialize()
        {
            agents = new DfsAgent[robots.Length];
            for (int i = 0; i < agents.Length; i++)
            {
                agents[i] = new DfsAgent(robots[i], memory, queue);
            }
            for (int i = 0; i < agents.Length; i++)
            {
                agents[i].Initialize();
            }
            memory = new SharedMemory();
            queue = new MessageQueue();
        }

        public void Start()
        {
            for (int i = 0; i < agents.Length; i++)
            {
                agents[i].Start();
            }
        }

        public void Stop()
        {
            for (int i = 0; i < agents.Length; i++)
            {
                agents[i].Stop();
            }
        }
    }
}
